<?php $this->set('title', 'Audience List'); ?>

<div class="header">Audience List: <?php echo $audiencelist_name;?></div>
<!-- Preregistered Users -->
<table border="0" cellpadding="5" cellspacing="0">
	<tr>
		<th>Username</th>
		<th>First Name</th>
		<th>Last Name</th>
	</tr>
<?php foreach ($preregistered_users as $preregistered_user): ?>
	<tr>
		<td><?php echo($preregistered_user['User']['username']); ?></td>
		<td><?php echo($preregistered_user['User']['firstname']); ?></td>
		<td><?php echo($preregistered_user['User']['lastname']); ?></td>
	</tr>
<?php endforeach; ?>
</table>
<!-- Search form -->
<?php echo $form->create('Survey', array('action' => 'audience_list', 'id' => 'id')); ?>
<table border="0" cellpadding=="0" cellspacing="0">
	<tr>
		<td class="leftcell">
			Username:
		</td>				
		<td class="rightcell">
			<?php echo($form->text('User.username', array('style' => 'width:200px;','value' => $searchName))); ?>
		</td>
	</tr>
	<tr>
		<td class="rightcell" colspan="2">
			<?php echo $form->end('Search') ?>
		</td>
	</tr>
</table>
<br />

<!-- Audience Member Search Results -->
<?php if($display) { ?>
<!-- Search results -->
<table style="" cellpadding="5" cellspacing="0" border="0">
	<tr> 
		<th>Name</th> 
		<th>Add to Audience List</th>
	</tr>
    <?php foreach($users as $user): ?> 
	<tr>
		<td><?php echo $user['User']['username']; ?></td>
		<td>
			<?php echo $html->link('Add',
		 	  array('controller'=>'surveys', 'action' => 'addUserToAudienceList', 
			  			$survey_id, $user['User']['id']));
			 ?>
		 </td>
	</tr>
	<?php endforeach; ?>
	<tr>
		<!-- Pagination -->
		<td colspan="3">
			<!-- Shows the page numbers -->
			<?php echo $paginator->numbers(); ?>
			<br />
			<!-- Shows the next and previous links -->
			<?php
				echo $paginator->prev('« Previous ', null, null, array('class' => 'disabledPageLink'));
				echo $paginator->next(' Next »', null, null, array('class' => 'disabledPageLink'));
			?>
			<br />
			<!-- prints X of Y, where X is current page and Y is number of pages -->
			<?php echo $paginator->counter(); ?>
		</td>
	</tr>
</table>
<?php } ?>

<div class="header">Load an Existing Audience List</div>
<table style="" cellpadding="5" cellspacing="0" border="0">
	<tr> 
		<th>Name</th>
		<th>Import Audience List</th>
	</tr>
    <?php foreach($usersAudienceLists as $usersAudienceList): ?> 
	<?php if($surveys_audiencelist_id != $usersAudienceList['Audiencelist']['id']){ ?>
	<tr>
		<td><?php echo $usersAudienceList['Audiencelist']['name']; ?></td>
		<td>
			<?php echo $html->link('Import',
		 	  array('controller'=>'surveys', 'action' => 'importAudiencelist', 
			  			$survey_id, $usersAudienceList['Audiencelist']['id'], $surveys_audiencelist_id));
			 ?>
		 </td>
	</tr>
	<?php }?>
	<?php endforeach; ?>
</table>